﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using TouchSocket.Http.WebSockets;
using WebSocketServer.WebSocketService.Message;

namespace WebSocketServer.WebSocketService.MessageHandlers
{
    public class MessageHandlerManager
    {
        private IMessageHandler _carImageHandler ;
        private IMessageHandler _carPositionHandler;
        public MessageHandlerManager()
        {
            _carImageHandler = new CarImageHandler();
            _handlerMap.Add(EventTopic.CarImage, _carImageHandler);
            _carPositionHandler = new PositionRequestHandler();
            _handlerMap.Add(EventTopic.CarPosition, _carPositionHandler);
        }
        private Dictionary<EventTopic,IMessageHandler> _handlerMap = new();
     

        public async Task HandleMessageAsync(IWebSocket socket,WebSocketData message)
        {
            if (_handlerMap.ContainsKey(message.MessageTopic!))
            {
                await _handlerMap[message.MessageTopic!].HandleAsync(socket, message);
            }
           

            Console.WriteLine($"[Unhandled] No handler found for message: {message}");
        }
    }
}
